# Base image for HDS portal
FROM        docker.repo:5000/ppc64le/centos_base
MAINTAINER  Andy Zhang <zch@cn.ibm.com>
ENV         container=docker
ARG         INST_DIR=/var/setup
ARG         PORTAL_TAR=clouddb.tgz
ARG         FILESERVER=http://172.16.0.164:8080/base_image
RUN         mkdir $INST_DIR
WORKDIR     $INST_DIR

# Install required yum packages
RUN         yum install -y pam gcc zlib zlib-devel python-pip python-devel httpd php mod_wsgi \
	        php-pdo php-devel libjpeg-devel postgresql-devel php-pecl-mongo cyrus-sasl \
	        cyrus-sasl-plain cyrus-sasl-gssapi mongodb-enterprise-tools pygobject3 git
# install cdsdk
ENV         INFORMIXDIR /opt/informix/
ENV         LD_LIBRARY_PATH $INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:\
$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/c++:$INFORMIXDIR/lib/client:$INFORMIXDIR/lib/dmi
ADD         $FILESERVER/clientsdk.tar clientsdk.tar
RUN         mkdir clientsdk && tar -xvf clientsdk.tar -C clientsdk && cd clientsdk \
            && ./installclientsdk -i silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR=$INFORMIXDIR
ENV	        INFORMIXSERVER  local_ifx
ENV	        INFORMIXSQLHOSTS $INFORMIXDIR/etc/sqlhosts.ifxserver
ENV	        INFORMIXCONTIME 15
COPY	    sqlhosts.ifxserver	$INFORMIXDIR/etc/

# install clouddb
#
ADD         $FILESERVER/$PORTAL_TAR clouddb.tgz
# Need to install fixed InformixDB because of hard coded checking in csdk version info
ADD         $FILESERVER/InformixDB-2.5.tar.gz InformixDB-2.5.tar.gz
RUN         mkdir /data && tar -xvf clouddb.tgz -C /data && [ -d /data/log ] || mkdir /data/log/ \
            && pip install InformixDB-2.5.tar.gz && pip install -r /data/requirements.txt  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN         /data/manage.py collectstatic --link --noinput

VOLUME      ["/data/", "/var/log/httpd/"]
WORKDIR     /data/
COPY        run_httpd.sh init.sh /
COPY        clouddb.conf    /etc/httpd/conf.d/
RUN         rm -fr $INST_DIR && chmod -v +x /*.sh && chown apache:apache $INFORMIXSQLHOSTS \
	        && chown -R apache:apache /data/
EXPOSE      80 443

ENTRYPOINT  ["/run_httpd.sh"]
LABEL        version="{{ image_version }}"
